class Solution
{
public:
    int findChampion(int n, vector<vector<int>> &edges)
    {
        vector<int> inDegrees(n, 0);
        for (auto &edge : edges)
        {
            inDegrees[edge[1]]++;
        }
        int zeroDegreeCount = 0;
        int champion = -1;
        for (int i = 0; i < n; i++)
        {
            if (inDegrees[i] == 0)
            {
                zeroDegreeCount++;
                champion = i;
            }
        }
        return zeroDegreeCount == 1 ? champion : -1;
    }
};